package cn.amos.core.business.impl;

import cn.amos.core.business.ProductBusiness;
import cn.amos.dao.entity.ProductEntity;
import cn.amos.dao.persistence.ProductMapper;
import cn.amos.facade.request.ProductForm;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author DaoyuanWang
 */
@Component("productBusiness")
public class ProductBusinessImpl implements ProductBusiness {

    @Resource
    private ProductMapper productDao;

    @Override
    public void addOne(ProductForm productForm) {
        if (productForm == null) {
            return;
        }
        ProductEntity productEntity = new ProductEntity();
        productEntity.setName(productForm.getName());
        productEntity.setPrice(productForm.getPrice());
        productEntity.setInfo(productForm.getInfo());
        productEntity.setExpand(productForm.getExpand());
        productEntity.setStatus(true);
        productEntity.setUpdateTime(new Date());
        productEntity.setCreateTime(new Date());

        productDao.insert(productEntity);
    }

    @Override
    public List<ProductEntity> getProductAll() {
        return productDao.selectListByExample(null);
    }

    @Override
    public void deleteOne(Integer id) {
        productDao.delete(id);
    }

}
